<template>
  <div class="form_box">
    <p>用户注册</p>
    <el-form :model="form" ref="myForm" label-width="70px" class="form">
      <el-form-item
        prop="account"
        label="手机号码"
      >
        <el-input v-model="form.mobile" type="number"></el-input>
      </el-form-item>
      <el-form-item
        prop="account"
        label="姓名"
      >
        <el-input v-model="form.nick"></el-input>
      </el-form-item>
      <el-form-item
        prop="pwd"
        label="密码"
      >
        <el-input v-model="form.pwd" type="password"></el-input>
      </el-form-item>
       <el-form-item
        prop="pwd"
        label="性别"
      >
        <el-radio v-model="form.sex" label="1">男</el-radio>
        <el-radio v-model="form.sex" label="2">女</el-radio>
      </el-form-item>
      <el-form-item>
        <el-button class="login" type="primary" @click="regist()">注册</el-button>
      </el-form-item>
      <div class="btns">
        <router-link class="regist" to='/login'>去登录</router-link>
      </div>
    </el-form>
  </div>
</template>

<script>
import { regist } from '../../apis/api.js'
export default {
  data() {
    return {
      form: {
        mobile: '',
        nick: '',
        pwd: '',
        sex: '1',
        securityCode: ''
      }
    }
  },
  methods: {
    regist() {
      console.log(this.form)
      if(!this.form.mobile || !this.form.nick || !this.form.pwd) {
        return this.$message.warning('请将注册信息填写完整')
      }
      if(this.form.mobile.length != 11) {
        return this.$message.warning('手机号格式错误')
      }
      if(this.form.pwd.length != 6) {
        return this.$message.warning('密码不能小于6位')
      }
      regist(this.form).then(res => {
        this.$refs['myForm'].resetFields();
        this.$message({
          message: '注册成功，即将跳转登录页面',
          type: 'success',
          duration: 980
        });
        setTimeout(() => {
          this.$router.replace('/login')
        }, 1000)
      })
    }
  }
}
</script>

<style scoped>
  .form_box {
    max-width: 350px;
    margin: 80px auto 0;
    overflow: hidden;
    padding: 5px 30px 5px 25px;
    background: rgba(255, 255, 255, .3);
    border-radius: 20px;
  }
  .form_box {
    padding-right: 40px;
    padding-bottom: 25px;
  }
  .form_box>p {
    font-size: 18px; font-weight: 600; margin-bottom: 40px;
  }
  .login {
    width: 200px;
  }
  .btns {
    display: flex;
    justify-content: flex-end;
    line-height: 20px;
  }
  a {
    font-size: 14px;
    color: #797464;
    text-decoration: none;
  }
  a:hover {
    color: #959081;
    text-decoration: underline;
  }
</style>
